package leetcode

// ListNode ...
type ListNode struct {
	Val  int
	Next *ListNode
}

// ListNode2Array ...
func (l *ListNode) ListNode2Array() (arr []int) {
	for node := l; node != nil; node = node.Next {
		arr = append(arr, node.Val)
	}
	return
}

// NewListNode ...
func NewListNode(arr []int) *ListNode {
	head := &ListNode{}
	node := head
	for _, v := range arr {
		node.Next = &ListNode{Val: v}
		node = node.Next
	}
	return head.Next
}
